﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

using QLTTAN.DTO;
namespace QLTTAN.DAL
{
    public class KhoaHocDAL
    {
        ConnectionData conn;

        public DataTable KhoaHoc_Load()
        {
            conn = new ConnectionData();
            return conn.GetData("KHOAHOC_LOAD");
        }

        public DataRow KhoaHoc_GetInfo(KhoaHocDTO KH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaKhoaHoc";
            value[0] = KH_DTO.MaKhoaHoc;

            return conn.GetData("KHOAHOC_GETINFO", name, value, Nparameter).Rows[0];
        }

        public int KhoaHoc_Insert(KhoaHocDTO KH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 3;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "TenKhoaHoc";
            value[0] = KH_DTO.TenKhoaHoc;
            name[1] = "NgayKhaiGiang";
            value[1] = KH_DTO.NgayKhaiGiang;
            name[2] = "NgayKetThuc";
            value[2] = KH_DTO.NgayKetThuc;

            return conn.UpdateData("KHOAHOC_INSERT", name, value, Nparameter);
        }

        public int KhoaHoc_Update(KhoaHocDTO KH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 4;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaKhoaHoc";
            value[0] = KH_DTO.MaKhoaHoc;
            name[1] = "TenKhoaHoc";
            value[1] = KH_DTO.TenKhoaHoc;
            name[2] = "NgayKhaiGiang";
            value[2] = KH_DTO.NgayKhaiGiang;
            name[3] = "NgayKetThuc";
            value[3] = KH_DTO.NgayKetThuc;

            return conn.UpdateData("KHOAHOC_UPDATE", name, value, Nparameter);
        }

        public int KhoaHoc_Delete(KhoaHocDTO KH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            
            name[0] = "MaKhoaHoc";
            value[0] = KH_DTO.MaKhoaHoc;

            return conn.UpdateData("KHOAHOC_DELETE", name, value, Nparameter);
        }
    }
}
